#include "stm32f10x.h"                  // Device header
#include "Delay.h"
#include "OLED.h"
#include "MyRTC.h"

uint32_t Alarm = 0;
uint8_t AlarmFlag = 0;

int main(void)
{
	OLED_Init();
	MyRTC_Init();
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);	

	OLED_ShowString(1, 1, "CNT:");
	OLED_ShowString(2, 1, "ALR:");
	OLED_ShowString(3, 1, "ALRF");
	PWR_WakeUpPinCmd(ENABLE);					// Enable唤醒引脚 引脚为PA0 默认弱下拉输入
	Alarm = RTC_GetCounter() + 10;				// 10s alarm
	RTC_SetAlarm(Alarm);						// 设置闹钟实现唤醒
	OLED_ShowNum(2, 5, Alarm, 10);

	while (1)
	{
		MyRTC_ReadTime();
		OLED_ShowNum(1, 5, RTC_GetCounter(), 10);	

		OLED_ShowString(4, 1, "Hello Bird!");
		Delay_ms(100);
		OLED_ShowString(4, 1, "           ");
		Delay_ms(100);
		OLED_ShowString(4, 1, "standby loading");
		Delay_ms(1000);
		OLED_Clear(); 

		PWR_EnterSTANDBYMode();  
	}
}
